﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Data.Linq.SqlClient;
using System.Data.Linq.Mapping;
using IronOne.SalesOne.BusinessObjects;

namespace IronOne.SalesOne.DataObjects
{
    public class LinqQuoDetails
    {

        public List<QuotationDetails> GetQuotationsDetails(string quotNo)
        {
            using (SODataDataContext db = DataContextFactory.CreateContext())
            {
                var query = from quotation in db.QuoDetailEntities

                            where quotation.QuotationNo == quotNo
                            select quotation;


                return query.Select(c => Mapper.ToQuotatioDetailsObject(c)).ToList();
            }
        }
        public List<string> GetLives(string QuotNum)
        {
            using (SODataDataContext db = DataContextFactory.CreateContext())
            {
                IQueryable<string> query = from quo in db.QuoDetailEntities
                                           where quo.QuotationNo==QuotNum
                                           select quo.Life;

                string[] life = { "MNLIFE", "SPOUSE", "CHILD1", "CHILD2", "CHILD3", "CHILD4", "CHILD5" };

                List<string> orgList = query.Distinct().ToList();
                List<string> tmpList = new List<string>();

                int i=0;
                foreach (string tmp in life)
                {
                    if (orgList.Contains(tmp))
                    {
                        tmpList.Insert(i, tmp);
                        i++;
                    }
                }

                return tmpList;
                //return query.Distinct().ToList();
            }
        }

       
    }
}
